js throw error

47

node js throw error -

FactoryController.prototype.create = function (callback) {
    //The throw is working, and the exception is returned.
    throw new Error('An error occurred'); //outside callback 
    try {
        this.check(function (check_result) {
            callback(check_result);
        });
    } catch (ex) {
        throw new Error(ex.toString());
    }
}

FactoryController.prototype.create = function (callback) {
    try {
        this.check(function (check_result) {
            //The throw is not working on this case to return the exception to the caller(parent)
            throw new Error('An error occurred'); //inside callback 
        });
    } catch (ex) {
        throw new Error(ex.toString());
    }
}

how to catch and throw error js -

try {
  throw new Error('Whoops!')
} catch (e) {
  console.error(e.name + ': ' + e.message)
}

throw new error( -

try {
  throw new Error('Whoops!')
} catch (e) {
  console.error(e.name + ': ' + e.message)
}

Comments

Submit
0 Comments